package com.spring.sunflower.dialog

import android.content.Context
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.ColorInt
import com.lxj.xpopup.core.CenterPopupView
import com.spring.sunflower.R

/**
 * Created by Kevin on 2021/8/6<br/>
 *
 * Describe:<br/>
 */
class NoticeDialog(
    context: Context,
    var listener: OnPermissionIntroClickListener?
) : CenterPopupView(context) {
    private var llContainer: LinearLayout? = null
    private var tvOK: TextView? = null
    private var tvCancel: TextView? = null
    private var tv: TextView? = null
    private var tvTitle: TextView? = null
    private var tvDesc: TextView? = null
    override fun getImplLayoutId(): Int {
        return R.layout.dialog_notice
    }

    override fun onCreate() {
        super.onCreate()
        llContainer = findViewById<LinearLayout>(R.id.llContainer)
        tvOK = findViewById(R.id.tvOK)
        tvCancel = findViewById(R.id.tvCancel)
        tv = findViewById(R.id.tv)
        tvTitle = findViewById<TextView>(R.id.tvTitle)
        tvDesc = findViewById<TextView>(R.id.tvDesc)
        xListener?.onCreateView()
        tvOK?.setOnClickListener {
            listener?.onClickOK()
            dismiss()
        }
        tvCancel?.setOnClickListener {
            listener?.onClickCancel()
            dismiss()
        }
    }

    fun getContainer(): LinearLayout {
        return llContainer!!
    }

    private var xListener: OnCreateViewListener? = null
    fun setOnCreateViewListener(l: OnCreateViewListener) {
        xListener = l
    }

    fun interface OnCreateViewListener {
        fun onCreateView()
    }

    fun setOKText(str: String) {
        if (str.isNullOrEmpty()) return
        tvOK?.text = str
        invalidate()
    }

    fun setCancelText(str: String) {
        if (str.isNullOrEmpty()) return
        tvCancel?.text = str
    }

    fun setHeadTitle(str: String) {
        if (str.isNullOrEmpty()) return
        tv?.text = str
        invalidate()
    }

    fun setTitleText(str: String) {
        if (str.isNullOrEmpty()) return
        tvTitle?.text = str
    }

    fun setTitleColor(@ColorInt color: Int) {
        tvTitle?.setTextColor(color)
    }

    fun setDescText(str: String) {
        if (str.isNullOrEmpty()) return
        tvDesc?.text = str
    }

    fun setDescColor(@ColorInt color: Int) {
        tvDesc?.setTextColor(color)
    }
}